package com.cqc.greendao05;

import com.cqc.greendao05.dao.gen.DaoMaster;
import com.cqc.greendao05.dao.gen.DaoSession;

/**
 * Created by ${cqc} on 2017/1/3.
 */

public class GreenDaoManager {

    private static DaoMaster.DevOpenHelper helper;
    private static DaoMaster daoMaster;
    private static DaoSession daoSession;
    private static GreenDaoManager greenDaoManager;

    private GreenDaoManager() {
        helper = new DaoMaster.DevOpenHelper(MyApplication.getContext(), "GreenDao_DB");
        daoMaster = new DaoMaster(helper.getWritableDb());
        daoSession = daoMaster.newSession();
    }

    public static GreenDaoManager getInstance() {
        if (greenDaoManager == null) {
            greenDaoManager = new GreenDaoManager();
        }
        return greenDaoManager;
    }

    public static DaoMaster.DevOpenHelper getDevOpenHelper() {
        return helper;
    }

    public static DaoMaster getDaoMaster() {
        return daoMaster;
    }

    public static DaoSession getDaoSession() {
        return daoSession;
    }

    public void closeDB() {
        if (helper != null) {
            helper.close();
        }
    }
}
